<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ include file="/common/_taglibs.jsp"%>
<%@ include file="/common/_meta.jsp"%>
<title>添加用户-用户管理</title>
<meta name="keywords" content="cms-simple CMS后台管理系统">
<meta name="description" content="cms-simple CMS后台管理系统">
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add" action="${ctx }/sys/addUser" method="post">
	<input type="hidden" name="id" value="${user.id }"/>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员账户：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<c:choose>
				<c:when test="${user.id == null || user.id == 0 }">
					<input type="text" class="input-text" value="${user.loginCode }" placeholder="" id="loginCode" name="loginCode">
				</c:when>
				<c:otherwise>
					<input type="text" class="input-text" value="${user.loginCode }" placeholder="" id="loginCode" name="loginCode" disabled="disabled">
				</c:otherwise>
			</c:choose>
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员名称：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="${user.userName }" placeholder="" id="userName" name="userName">
		</div>
	</div>
	<c:if test="${user.id == null}">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>初始密码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="password" class="input-text" placeholder="密码" id="password" name="password">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="password" class="input-text"  placeholder="确认新密码" id="password2" name="password2">
			</div>
		</div>
	</c:if>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">角色：</label>
		<div class="formControls col-xs-8 col-sm-9">
		<c:forEach items="${roleList }" var="role">
			<div class="check-box">
				<c:choose>
					<c:when test="${role.chose }">
						<input id="checkbox-${role.id }" type="checkbox" name="roles" value="${role.id }" checked>
					</c:when>
					<c:otherwise>
						<input id="checkbox-${role.id }" type="checkbox" name="roles" value="${role.id }">
					</c:otherwise>
				</c:choose>
			    <label for="checkbox-${role.id }">${role.name }</label>
			</div>
		</c:forEach>
		</div>
	</div>
	<!-- 
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">备注：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<textarea name="" cols="" rows="" class="textarea"  placeholder="说点什么...100个字符以内" dragonfly="true" onKeyUp="textarealength(this,100)"></textarea>
			<p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
		</div>
	</div>
	 -->
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
		</div>
	</div>
	</form>
</article>
<script type="text/javascript" src="${ctx }/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${ctx }/lib/jquery/1.9.1/jquery.form.js"></script> 
<script type="text/javascript" src="${ctx }/lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="${ctx }/lib/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="${ctx }/lib/jquery.validation/1.14.0/jquery.validate.min.js"></script>
<script type="text/javascript" src="${ctx }/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="${ctx }/lib/jquery.validation/1.14.0/messages_zh.min.js"></script>
<script type="text/javascript" src="${ctx }/static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="${ctx }/static/h-ui.admin/js/H-ui.admin.js"></script> 
<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript">
$(function(){
	$("#loginCode").on("change", function(){
		var loginCode = $(this).val();
		$.ajax({
			type: "POST",
			url: "${ctx}/sys/checkUserExist",
			data: {"loginCode": loginCode},
			success: function(data){
				if(data.state != 1){
					$(this).attr("class", "input-text error").attr("aria-invalid", "true");
					layer.msg(data.msg,{icon:1,time:1000});
				}
			}
		});
	});
	
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-admin-add").validate({
		rules:{
			loginCode:{
				required:true,
				minlength:6,
				maxlength:20
			},
			userName:{
				required:true,
				minlength:4,
				maxlength:10
			},
			password:{
				required:true,
			},
			password2:{
				required:true,
				equalTo: "#password"
			}
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit();
			var index = parent.layer.getFrameIndex(window.name);
			parent.$('.btn-refresh').click();
			parent.layer.close(index);
		}
	});
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
